﻿package com.pool.core 
{
	import com.pool.data.RoomMgr;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import com.pool.events.DeskEvent;
	import flash.text.TextField;
	import com.pool.data.UserDataMgr;
	import org.dm.display.DisplayMgr;
	import org.dm.general.ClassGather;
	import SpLib.ObjSys.NetObjMgr;
	
	import flash.text.TextFormat;
	/**
	 * ...
	 * @author Scott
	 */
	public class Desks extends EventDispatcher
	{
		protected var _display:Sprite;
		private var _roomName:TextField;
		private var _findDesk:SimpleButton;
		private var _changeRoom:SimpleButton;
		private var _returnBtn:SimpleButton;
		
		private var _desksDisplay:Array;
		
		public function Desks() 
		{
			super();
			_display = DisplayMgr.getDisplay("desks.bg","win.RoomWin");
			_findDesk = _display.getChildByName("FindDesk") as SimpleButton;
			_changeRoom = _display.getChildByName("ChangeRoom") as SimpleButton;
			
			_roomName = new TextField();
			_roomName.x = 541.45;
			_roomName.y = 43.1;
			_roomName.width = 200;
			_roomName.embedFonts = true;
			_roomName.selectable = false;
			_roomName.defaultTextFormat = new TextFormat("fanzhen", 25, 0xffffff);
			_display.addChild(_roomName);
			
			//设置返回按钮
			_returnBtn = DisplayMgr.getDisplay("desks.return", "btn.ReturnBtn");
			_returnBtn.x = _display.width - 30;
			_returnBtn.y = 5;
			_display.addChild(_returnBtn);
			
			_findDesk.addEventListener(MouseEvent.CLICK, onLoginDesk);
			_changeRoom.addEventListener(MouseEvent.CLICK, onLoginDeskOut);
			
			//_desksDisplay.push(new MinDesk(30, 0));
			
			_display.addChild((new MinDesk(30, 0)).display);
			_display.addChild((new MinDesk(245,145)).display);
			_display.addChild((new MinDesk(30, 145)).display);
			_display.addChild((new MinDesk(245, 0)).display);
			_display.addChild((new MinDesk(30, 290)).display);
			_display.addChild((new MinDesk(245, 290)).display);
		}
		
		public function init():void 
		{
			ClassGather.reg("net.minDesk", MinDesk);
			RoomMgr.Instance.join();
			_roomName.text = "新手球场 05";
			
			
		}
		
		public function onLoginDesk(e:MouseEvent):void 
		{
			dispatchEvent(new DeskEvent(DeskEvent.LOINGAME));
		}
		
		public function onLoginDeskOut(e:MouseEvent):void
		{
			dispatchEvent(new DeskEvent(DeskEvent.LOINGAME));
		}
		
		public function get display():Sprite
		{
			return this._display; 
		}
	}

}